package com.jeecg.p3.system.poster.service;

import com.jeecg.p3.base.util.ComCode;
import com.jeecg.p3.system.poster.dao.PosterTypeDao;
import com.jeecg.p3.system.poster.entity.PosterType;
import com.jeecg.p3.system.util.UuidUtils;
import org.jeecgframework.p3.core.utils.common.PageList;
import org.jeecgframework.p3.core.utils.common.PageQuery;
import org.jeecgframework.p3.core.utils.common.PageQueryWrapper;
import org.jeecgframework.p3.core.utils.common.Pagenation;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 海报类型服务层
 */
@Service
public class PosterTypeService {
    @Resource
    private PosterTypeDao posterTypeDao;

    /**
     * 分页查询海报分类信息
     * @param pageQuery
     * @return
     */
    public PageList<PosterType> queryPageList(PageQuery<PosterType> pageQuery) {
        PageList<PosterType> result = new PageList<PosterType>();
        Integer itemCount = posterTypeDao.count(pageQuery);
        PageQueryWrapper<PosterType> wrapper = new PageQueryWrapper<PosterType>(pageQuery.getPageNo(), pageQuery.getPageSize(),itemCount, pageQuery.getQuery());
        List<PosterType> list = posterTypeDao.queryPageList(wrapper);
        Pagenation pagenation = new Pagenation(pageQuery.getPageNo(), itemCount, pageQuery.getPageSize());
        result.setPagenation(pagenation);
        result.setValues(list);
        return result;
    }

    /**
     * 新增海报类型信息
     * @param posterType
     */
    public void doAdd(PosterType posterType) {
        posterType.setId(UuidUtils.getId());
        posterType.setStatus(ComCode.statusNormal);
        posterTypeDao.insert(posterType);
    }

    /**
     * 根据id查询海报分类信息
     * @param id
     * @return
     */
    public PosterType findById(Long id) {
        return posterTypeDao.get(id);
    }


    /**
     * 编辑海报信息
     * @param posterType
     */
    public void doEdit(PosterType posterType) {
        posterTypeDao.update(posterType);
    }

    /**
     * 删除海报分类信息
     * @param posterType
     */
    public void doDelete(PosterType posterType) {
        posterType.setStatus("0");
        posterTypeDao.update(posterType);
    }

    /**
     * 根据code查询唯一的海报设计类型
     * @param code
     * @return
     */
    public PosterType findByCode(String code) {
        return posterTypeDao.findByCode(code);
    }
}
